home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#47 (Aug 89)
/
PREC Code
/
About.p
next >
Wrap
Text File
|
1989-06-14
|
7KB
|
177 lines
unit About;
{File name: About.p }
{Function: Handle a dialog}
{History: 6/10/89 Original by Prototyper. }
{ }
interface
procedure D_About;
implementation
const {These are the item numbers for controls in the Dialog}
I_OK = 1;
I_x = 2;
I_Icon6 = 3;
var
ExitDialog: boolean; {Flag used to exit the Dialog}
DoubleClick: boolean; {Flag to say that a double click on a list happened}
MyPt: Point; {Current list selection point}
MyErr: OSErr; {OS error returned}
{===========================================================}
function MyFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
var
tempRect: Rect;
begin
MyFilter := FALSE;
if (theEvent.what = MouseDown) then{Only do on a mouse click}
begin
MyPt := theEvent.where;{Get the point where the mouse was clicked}
GlobalToLocal(MyPt); {Convert global to local}
end;
end;
{===========================================================}
procedure D_About;
var
GetSelection: DialogPtr;{Pointer to this dialog}
tempRect: Rect; {Temporary rectangle}
DType: Integer; {Type of dialog item}
Index: Integer; {For looping}
DItem: Handle; {Handle to the dialog item}
CItem, CTempItem: controlhandle;{Control handle}
sTemp: Str255; {Get text entered, temp holding}
itemHit: Integer; {Get selection}
temp: Integer; {Get selection, temp holding}
dataBounds: Rect; {Rect to setup the list}
cSize: Point; {Pointer to a cell in a list}
Icon_Handle: Handle; {Temp handle to read an Icon into}
NewMouse: Point; {Mouse location during tracking Icon presses}
InIcon: boolean; {Flag to say pressed in an Icon}
ThisEditText: TEHandle; {Handle to get the Dialogs TE record}
TheDialogPtr: DialogPeek;{Pointer to Dialogs definition record, contains the TE record}
{This is an update routine for non-controls in the dialog}
{This is executed after the dialog is uncovered by an alert}
procedure Refresh_Dialog; {Refresh the dialogs non-controls}
var
rTempRect: Rect; {Temp rectangle used for drawing}
begin
SetPort(GetSelection); {Point to our dialog window}
GetDItem(GetSelection, I_OK, DType, DItem, tempRect);{Get the item handle}
PenSize(3, 3); {Change pen to draw thick default outline}
InsetRect(tempRect, -4, -4);{Draw outside the button by 1 pixel}
FrameRoundRect(tempRect, 16, 16); {Draw the outline}
PenSize(1, 1); {Restore the pen size to the default value}
end;
begin {Start of dialog handler}
GetSelection := GetNewDialog(2, nil, Pointer(-1));{Bring in the dialog resource}
ShowWindow(GetSelection);{Open a dialog box}
SelectWindow(GetSelection);{Lets see it}
SetPort(GetSelection); {Prepare to add conditional text}
TheDialogPtr := DialogPeek(GetSelection);{Get to the inner record}
ThisEditText := TheDialogPtr^.textH;{Get to the TE record}
HLock(Handle(ThisEditText));{Lock it for safety}
ThisEditText^^.txSize := 12;{TE Point size}
TextSize(12); {Window Point size}
ThisEditText^^.txFont := systemFont;{TE Font ID}
TextFont(systemFont); {Window Font ID}
ThisEditText^^.txFont := 0;{TE Font ID}
ThisEditText^^.fontAscent := 12;{Font ascent}
ThisEditText^^.lineHeight := 12 + 3 + 1;{Font ascent + descent + leading}
HUnLock(Handle(ThisEditText));{UnLock the handle when done}
{Setup initial conditions}
Refresh_Dialog; {Draw any Lists, popups, lines, or rectangles}
ExitDialog := FALSE; {Do not exit dialog handle loop yet}
repeat {Start of dialog handle loop}
ModalDialog(nil, itemHit);{Wait until an item is hit}
GetDItem(GetSelection, itemHit, DType, DItem, tempRect);{Get item information}
CItem := Pointer(DItem);{Get the control handle}
{Handle it real time}
if (ItemHit = I_OK) then{Handle the Button being pressed}
begin
{?? Code to handle this button goes here}
ExitDialog := TRUE;{Exit the dialog when this selection is made}
Refresh_Dialog;
end; {End for this item selected}
if (ItemHit = I_Icon6) then{Handle the Icon}
begin
Icon_Handle := GetIcon(10032);{Get Hilighted Icon into memory}
if (Icon_Handle <> nil) then{Only do if we got the resource OK}
begin {Get ready to plot the hilighted icon}
EraseRect(tempRect);{Erase the original icon}
PlotIcon(tempRect, Icon_Handle);{Draw the hilighted icon}
end; {End of drawing hilighted icon}
InIcon := TRUE;{Flag as mouse in the Icon}
repeat {Start of mouse tracking routine}
GetMouse(NewMouse);{Get latest mouse position}
if (PtInRect(NewMouse, tempRect)) then{See if still over the Icon}
begin {...yes, over the Icon}
if not (InIcon) then{See if mouse was out of Icon}
begin{...yes, so it is unhilighted}
Icon_Handle := GetIcon(10032);{Get Hilighted Icon into memory}
if (Icon_Handle <> nil) then{Only do if we have a hilighted Icon}
begin{...yes, have hilighted Icon}
EraseRect(tempRect);{Erase the unhilighted icon}
PlotIcon(tempRect, Icon_Handle);{Draw the hilighted icon}
end;{End of Draw the hilighted icon}
InIcon := TRUE;{Flag that we drew the hilighted icon}
end;{}
end {}
else if InIcon then{Then draw unhilighted Icon}
begin {Start drawing unhilighted Icon}
Icon_Handle := GetIcon(32);{Get standard Icon into memory}
if (Icon_Handle <> nil) then{Only do if we have the Icon}
begin{...yes, have hilighted Icon}
EraseRect(tempRect);{Erase the hilighted icon}
PlotIcon(tempRect, Icon_Handle);{Draw the standard icon}
end;{End of Draw the icon}
InIcon := FALSE;{Flag as showing the unhilighted icon}
end; {}
until not (StillDown);{Loop till mouse button is released}
{}
if (PtInRect(NewMouse, tempRect)) then{See if released in the Icon}
begin {...yes, released in the Icon}
Refresh_Dialog; {Refresh anything now uncovered}
end; {End of released in the Icon}
Icon_Handle := GetIcon(32);{Get standard Icon into memory}
if (Icon_Handle <> nil) then{Only do if we have the Icon}
begin {...yes, have hilighted Icon}
EraseRect(tempRect);{Erase the hilighted icon}
PlotIcon(tempRect, Icon_Handle);{Draw the standard icon}
end; {End of Draw the icon}
end; {End for this item selected}
until ExitDialog; {Handle dialog items until exit selected}
{Get results after dialog}
DisposDialog(GetSelection);{Flush the dialog out of memory}
end; {End of procedure}
end. {End of unit}